using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Controladoras;
using EntidadesTO;
using System.Collections.Generic;

public partial class FrmModificarCondominioPopup : System.Web.UI.UserControl
{
    private CondominioTO condominioLocal;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CargarControles();
            this.CascadingDropDown1.SelectedValue = null;
            this.CascadingDropDown2.ContextKey = null;
            this.CascadingDropDown3.ContextKey = null;
            this.CascadingDropDown4.ContextKey = null;

            if (Session["Accion"].ToString() == "Visualizar" || Session["Accion"].ToString() == "Evaluar")
            {
                DeshabilitarControles();
            }

        }
    }

    public void CambiarTituloVisualizar()
    {
        this.Label50.Text = "Visualizar Detalle Condominio";
    }

    private void CargarControles()
    {
        DocumentoLegalMantenedor.ObtenerInstancia().CargarLista();
        this.cmbDocumentoIdent.DataSource = DocumentoLegalMantenedor.ObtenerInstancia().ListaDocumentoLegal;
        this.cmbDocumentoIdent.DataBind();
    }

    public CondominioTO ObtenerCondominio()
    {
        CondominioTO condominio = new CondominioTO();
        condominio.CodDocumento = Int32.Parse(this.cmbDocumentoIdent.SelectedValue);
        condominio.NumDocumento = this.txtPpDocumento.Text;
        condominio.Nombres = this.txtPpNombres.Text;
        condominio.Porcentaje = Decimal.Parse(this.txtPpPorcCondominio.Text);
        condominio.Direccion = this.txtPpDireccion.Text;
        condominio.SecDistrito = Int32.Parse(this.cmbPpDistrito.SelectedValue);
        condominio.SecPais = Int32.Parse(this.cmbPpPais.SelectedValue);
        condominio.SecDepartamento = Int32.Parse(this.cmbPpDepartamento.SelectedValue);
        condominio.SecProvincia = Int32.Parse(this.cmbPpProvincia.SelectedValue);
        condominio.DesDocumento = this.cmbDocumentoIdent.SelectedItem.ToString();
        condominio.DesDistrito = this.cmbPpDistrito.SelectedItem.ToString();
        condominio.NumCondominio = 0;

        return condominio;
    }

    public void LimpiarFiltros()
    {
        this.cmbDocumentoIdent.SelectedValue = "1";
        this.txtPpDocumento.Text = "";
        this.txtPpNombres.Text = "";
        this.txtPpPorcCondominio.Text = "";
        this.txtPpDireccion.Text = "";
        this.CascadingDropDown1.SelectedValue = null;
    }

    public void MostrarParaActualizar(CondominioTO pCondominio)
    {
        this.condominioLocal = pCondominio;
        this.cmbDocumentoIdent.SelectedValue = condominioLocal.CodDocumento.ToString();
        this.txtPpDocumento.Text = condominioLocal.NumDocumento;
        this.txtPpNombres.Text = condominioLocal.Nombres;
        this.txtPpPorcCondominio.Text = condominioLocal.Porcentaje.ToString();
        this.CascadingDropDown1.SelectedValue = condominioLocal.SecPais.ToString();
        this.CascadingDropDown2.ContextKey = condominioLocal.SecDepartamento.ToString();
        this.CascadingDropDown3.ContextKey = condominioLocal.SecProvincia.ToString();
        this.CascadingDropDown4.ContextKey = condominioLocal.SecDistrito.ToString();
        this.txtPpDireccion.Text = condominioLocal.Direccion;
        //this.txtCondominio.Text = condominioLocal.NumCondominio.ToString();
        Session["numCondominio"] = condominioLocal.NumCondominio.ToString();
    }

    public CondominioTO obtenerCondominioModificado()
    {
        this.condominioLocal = new CondominioTO();

        //condominioLocal.NumCondominio = Int32.Parse(this.txtCondominio.Text);
        condominioLocal.NumCondominio = Int32.Parse(Session["numCondominio"].ToString());
        condominioLocal.CodDocumento = Int32.Parse(this.cmbDocumentoIdent.SelectedValue);
        condominioLocal.NumDocumento = this.txtPpDocumento.Text;
        condominioLocal.Nombres = this.txtPpNombres.Text;
        condominioLocal.Porcentaje = Decimal.Parse(this.txtPpPorcCondominio.Text);
        condominioLocal.Direccion = this.txtPpDireccion.Text;
        condominioLocal.SecDistrito = Int32.Parse(this.cmbPpDistrito.SelectedValue);
        condominioLocal.SecPais = Int32.Parse(this.cmbPpPais.SelectedValue);
        condominioLocal.SecDepartamento = Int32.Parse(this.cmbPpDepartamento.SelectedValue);
        condominioLocal.SecProvincia = Int32.Parse(this.cmbPpProvincia.SelectedValue);
        condominioLocal.DesDocumento = this.cmbDocumentoIdent.SelectedItem.ToString();
        condominioLocal.DesDistrito = this.cmbPpDistrito.SelectedItem.ToString();

        return condominioLocal;
    }

    private void DeshabilitarControles()
    {
        this.cmbDocumentoIdent.Enabled = false;
        this.txtPpDocumento.Enabled = false;
        this.txtPpNombres.Enabled = false;
        this.txtPpPorcCondominio.Enabled = false;
        this.txtPpDireccion.Enabled = false;
    }
}
